package com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblehttp;

import com.test.fundible.fundible_00_utils.FundibleConfigs;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class FundibleASPostSyncTsk {

    private final String url;
    public String yGsS="";
    public String fW19="";
    public String sCqZ="";
    public String tWLK="";
    public String e53d="";
    private final String taskId;
    public String u29J="";
    public String f5ji="";
    private final String body;

    public char o76q='l';
    public char t7Nv='Ä';
    public char x0iC='y';
    public boolean dxWw=true;
    public float rJbu=0.031221211f;
    public char wOyK='©';
    public char cWAm='b';
    public String ghaer;

    public void test(){
        if ((int)o76q+(int)cWAm>225){
            setGhaer(String.valueOf(dxWw));
        }
    }

    public FundibleASPostSyncTsk(String taskId, String url, String body) {
        this.taskId = taskId;
        this.url = url;
        this.body = body;
    }

    public FundibleASResp getASResp() {
        try {
            URL url = new URL(this.url);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setDoInput(true);
            urlConnection.setDoOutput(true);
            urlConnection.setUseCaches(false);
            urlConnection.setReadTimeout(180000);
            urlConnection.setConnectTimeout(120000);
            urlConnection.setRequestMethod("POST");
            urlConnection.setRequestProperty("Charset", "UTF-8");
            urlConnection.setRequestProperty("Connection", "Keep-Alive");
            urlConnection.setRequestProperty("Content-Type", "application/json");
//            urlConnection.setRequestProperty("Content-Length", (body.getBytes()).length + "");
            urlConnection.setRequestProperty("product", FundibleConfigs.fundibleProduct);
            urlConnection.getOutputStream().write(body.getBytes());
            urlConnection.getOutputStream().flush();
            urlConnection.getOutputStream().close();
            try {
                int resCode = urlConnection.getResponseCode();
                if (resCode == HttpURLConnection.HTTP_OK) {
                    InputStream in = urlConnection.getInputStream();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                    StringBuilder result = new StringBuilder();
                    String line;
                    while ((line = reader.readLine()) != null) {
                        result.append(line);
                    }

//                    JSONObject resultObj = new JSONObject(result.toString());
                    return new FundibleASResp(this.taskId, new JSONObject());
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                urlConnection.getInputStream().close();
                urlConnection.disconnect();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return new FundibleASResp(this.taskId, null);
    }

    public void setyGsS(String yGsS) {
        this.yGsS = yGsS;
    }

    public void setfW19(String fW19) {
        this.fW19 = fW19;
    }

    public void setsCqZ(String sCqZ) {
        this.sCqZ = sCqZ;
    }

    public void settWLK(String tWLK) {
        this.tWLK = tWLK;
    }

    public void setE53d(String e53d) {
        this.e53d = e53d;
    }

    public void setU29J(String u29J) {
        this.u29J = u29J;
    }

    public void setF5ji(String f5ji) {
        this.f5ji = f5ji;
    }

    public String getUrl() {
        return url;
    }

    public String getyGsS() {
        return yGsS;
    }

    public String getfW19() {
        return fW19;
    }

    public String getsCqZ() {
        return sCqZ;
    }

    public String gettWLK() {
        return tWLK;
    }

    public String getE53d() {
        return e53d;
    }

    public String getTaskId() {
        return taskId;
    }

    public String getU29J() {
        return u29J;
    }

    public String getF5ji() {
        return f5ji;
    }

    public String getBody() {
        return body;
    }

    public void setO76q(char o76q) {
        this.o76q = o76q;
    }

    public void setT7Nv(char t7Nv) {
        this.t7Nv = t7Nv;
    }

    public void setX0iC(char x0iC) {
        this.x0iC = x0iC;
    }

    public void setDxWw(boolean dxWw) {
        this.dxWw = dxWw;
    }

    public void setrJbu(float rJbu) {
        this.rJbu = rJbu;
    }

    public void setwOyK(char wOyK) {
        this.wOyK = wOyK;
    }

    public void setcWAm(char cWAm) {
        this.cWAm = cWAm;
    }

    public void setGhaer(String ghaer) {
        this.ghaer = ghaer;
    }
}
